<template>
  <div class="chaperone-item">
    <!-- 发布用户 -->
    <div class="person-info">
      <div class="head" @click="$router.push('/authorcenter/' + user_id)">
        <img :src="head_url" alt="" />
      </div>
      <div class="nick-name">
        <span class="nick">{{ nick_name }}</span>
        <span class="release-time">{{ release }}</span>
      </div>
    </div>
    <!-- 地址信息 -->
    <div class="address-box" v-if="address !== ''">
      <!-- 邮箱图片 -->
      <div class="email-box">
        <img src="@/assets/head/Al2.png" alt="" />
      </div>
      <!-- 约伴详情 -->
      <div class="detail">
        <div class="requirement">
          <span class="time">{{ goTime }}</span>
          <span class="pay-type">{{ payType }}</span>
          <span class="person-count">{{ person_count_type }}人</span>
          <span class="sex-type">{{ sexType }}</span>
        </div>
        <div class="address" @click="$router.push('/businesses/' + bus_id)">
          <div class="icon">
            <img src="@/assets/head/3g.png" alt="" />
          </div>
          <span>{{ address }}</span>
        </div>
      </div>
    </div>
    <!-- 发布内容 -->
    <div class="content">{{ content }}</div>
    <!-- 活动信息 -->
    <div class="feed-info" v-if="title" @click="$router.push('/feeds/' + id)">
      <div class="feed-pic">
        <img :src="feed_url" alt="" />
      </div>
      <div class="feed-content">
        <div class="title">{{ title }}</div>
        <div class="text">{{ text }}</div>
        <div class="time-count">
          <span class="time">{{ end_time }}</span>
          <span class="count">{{ count }}人想去</span>
        </div>
      </div>
    </div>
    <!-- 操作选项 -->
    <div class="options">
      <div>
        <span class="icon">
          <img src="@/assets/head/Dm.png" alt="" />
        </span>
        <span class="text">我想去</span>
        <span v-if="like_count !== 0">({{ like_count }})</span>
      </div>
      <div>
        <span class="icon">
          <img src="@/assets/head/lb.png" alt="" />
        </span>
        <span class="text">直接约</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    head_url: String,
    nick_name: String,
    release_time: Number,
    address: String,
    title: String,
    text: String,
    content: String,
    end_time: String,
    count: Number,
    feed_url: String,
    sex_type: Number,
    invitation_time: Number,
    fee_type: Number,
    like_count: Number,
    person_count_type: Number,
    id: Number,
    user_id: Number,
    bus_id: Number
  },
  methods: {
    formatDay(day) {
      switch (day) {
        case 1:
          return '星期一'
        case 2:
          return '星期二'
        case 3:
          return '星期三'
        case 4:
          return '星期四'
        case 5:
          return '星期五'
        case 6:
          return '星期六'
        case 0:
          return '星期日'
      }
    }
  },
  computed: {
    release() {
      const time = new Date().getTime() / 1000 - this.release_time
      if (time / 3600 >= 1) {
        if (Math.floor(time / 3600 / 24) > 0) {
          return Math.floor(time / 3600 / 24) + '天前'
        } else {
          return Math.floor(time / 3600) + '小时前'
        }
      } else if (time / 60 >= 0) {
        return Math.floor(time / 60) + '分钟前'
      } else {
        return '刚刚发布'
      }
    },
    sexType() {
      if (this.sex_type == 2) {
        return '仅限女生'
      } else {
        return '性别不限'
      }
    },
    goTime() {
      if (this.invitation_time !== 0) {
        const date = new Date(this.invitation_time * 1000)
        let y = date.getFullYear()
        let m = date.getMonth() + 1
        let d = date.getDate()
        let day = date.getDay()
        m = m < 10 ? '0' + m : m
        d = d < 10 ? '0' + d : d
        return `${y}-${m}-${d} ${this.formatDay(day)}`
      } else {
        return '任意时间'
      }
    },
    payType() {
      if (this.fee_type == 1) {
        return '我买单'
      } else {
        return 'AA'
      }
    }
  }
}
</script>

<style lang="less" scoped>
.chaperone-item {
  border: 1px solid #ccc;
  box-shadow: 0 5px 10px #d8d8d8;
  margin-bottom: 10px;
  padding: 10px;

  img {
    height: 100%;
    width: 100%;
  }

  .person-info {
    display: flex;

    .head {
      height: 40px;
      width: 40px;
      border-radius: 999px;
      overflow: hidden;
    }
    .nick-name {
      line-height: 20px;
      margin-left: 10px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      color: #333;
      font-size: 14px;
    }
  }
  .address-box {
    display: flex;
    margin-top: 10px;
    align-items: center;

    .email-box {
      height: 20px;
      width: 20px;
    }
    .detail {
      display: flex;
      flex-direction: column;
      line-height: 20px;
      margin-left: 20px;

      .requirement {
        color: #000;
        font-size: 14px;

        span {
          margin-right: 5px;
        }
      }
      .address {
        display: flex;

        .icon {
          height: 14px;
          width: 14px;
          align-self: center;
        }
        span {
          font-size: 14px;
          font-weight: 500;
          margin-left: 3px;
          color: #9aa6bb;
        }
      }
    }
  }
  .content {
    margin-top: 5px;
    font-size: 14px;
    color: #333;
    height: 24px;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 24px;
  }

  .feed-info {
    margin-top: 10px;
    display: flex;
    .feed-pic {
      height: 60px;
      width: 60px;
    }
    .feed-content {
      padding-left: 10px;
      line-height: 20px;
      font-size: 12px;
      color: #717171;
      flex: 1;
      background-color: #f8f8f8;
      .title {
        color: #000;
        font-size: 14px;
        font-weight: 700;
      }
      .time {
        margin-right: 10px;
      }
    }
  }
  .options {
    padding-top: 20px;
    padding-bottom: 5px;
    display: flex;
    align-items: center;
    justify-content: space-around;

    div {
      display: flex;
      align-items: center;

      .icon {
        height: 16px;
        width: 16px;
        margin-right: 5px;
      }
      .text {
        color: #333;
        font-size: 14px;
        font-weight: 500;
      }
    }
  }
}
</style>
